package net.dgg.rz.common.checkRecord.service;


import net.dgg.framework.tac.utils.idutil.DggKeyWorker;
import net.dgg.rz.common.checkRecord.dao.CheckRecordDao;
import net.dgg.rz.common.checkRecord.entity.CheckRecord;
import net.dgg.tmd.foundation.platform.org.entity.OrganizationEntity;
import net.dgg.tmd.foundation.platform.org.service.OrganizationManager;
import net.dgg.tmd.foundation.platform.session.SessionManager;
import net.dgg.tmd.foundation.platform.user.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;


/**
 * 系统操作日志Service
 *
 * @Author:CP
 * @Date: Created in 2019/2/26 14:10
 * @Copyright © dgg group.All Rights Reserved. 版权信息
 */
@Service
public class CheckRecordService {

    @Autowired
    private SessionManager sessionManager;

    @Autowired
    private CheckRecordDao checkRecordDao;

    @Autowired
    private OrganizationManager organizationManager;

    /**
     * 保存放大镜查看记录
     * @param checkRecord
     */
    @Transactional
    @SuppressWarnings("all")
    public void saveCheckRecord(CheckRecord checkRecord){
        UserEntity userEntity = sessionManager.getCurrentUser();
        OrganizationEntity operatedOrgan = organizationManager.findOrgEntityByOrgId(userEntity.getOrgId());

        checkRecord.setId(DggKeyWorker.nextId());
        checkRecord.setOperaterId(userEntity.getId());
        checkRecord.setOperaterName(userEntity.getRealName() + userEntity.getLoginName());
        checkRecord.setOperaterOrgId(operatedOrgan.getId());
        checkRecord.setOperaterOrgName(operatedOrgan.getName());
        checkRecord.setOperateTime(new Date());

        checkRecordDao.insert(checkRecord);
    }

}
